package model;

import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;

/** @author Bogdan

 */
public class Machine {

	private int code, sketchNumber;
	private String model, manufacturer, manualLocation;
	private List<SparePart> parts = new ArrayList<SparePart>();
	private List<Repair> repairs = new ArrayList<Repair>();
	private GregorianCalendar downtime;
	private boolean state = true;

	/**
	 * <b>Example:</b><br>
	 * <code>  Machine machine = new Machine(code, model, manufacturer, manual, sketch); </code>

	 * @param int code = the ID number
	 *  </br> String model = machine model
	 * 	</br> String manufacturer = the machine	manufacturer
	 *  </br> String manualLocation = where to find the machine's manual
	 *  </br> int sketchNumber = the ID for the machine's sketch / drawing
	 *  @since this morning	   
	 */
	public Machine(int code, String model, String manufacturer, String manual,
			int sketch) {
		this.code = code;
		this.model = model;
		this.manufacturer = manufacturer;
		this.manualLocation = manual;
		this.sketchNumber = sketch;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public int getSketchNumber() {
		return sketchNumber;
	}

	public void setSketchNumber(int sketchNumber) {
		this.sketchNumber = sketchNumber;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getManufacturer() {
		return manufacturer;
	}

	public void setManufacturer(String manufacturer) {
		this.manufacturer = manufacturer;
	}

	public String getManualLocation() {
		return manualLocation;
	}

	public void setManualLocation(String manualLocation) {
		this.manualLocation = manualLocation;
	}

	public List<Repair> getRepairs() {
		return repairs;
	}

	public void addRepair(Repair repair) {
		if (!repairs.contains(repair))
			repairs.add(repair);
		repair.setMachine(this);
	}

	public void removeRepair(Repair repair) {
		if (repairs.contains(repair))
			repairs.remove(repair);
		repair.setMachine(null);
	}

	/**
	 * @author Bogdan
	 * @param sp - the SparePart to be added
	 */
	public void addSparePart(SparePart sp) {
		if (!parts.contains(sp))
			parts.add(sp);
	}

	/**
	 * @author Bogdan
	 * @param sp - the SparePart to be removed
	 */
	public void removeSparePart(SparePart sp) {
		if (parts.contains(sp))
			parts.remove(sp);
	}

	/**
	 * @author Bogdan
	 * @return The list of spareParts
	 */
	public List<SparePart> returnParts() {
		return parts;
	}

	public void updateMachine(int code, String model, String manufacturer,
			String manualLocation, int sketch) {
		this.code = code;
		this.model = model;
		this.manufacturer = manufacturer;
		this.manualLocation = manualLocation;
		this.sketchNumber = sketch;
	}

	public boolean getState() {
		return state;
	}

	public void setState(boolean state) {
		this.state = state;
	}

	public String toString() {
		String temp;
		if (this.state == true) temp = "Working";
		else temp = "Broken";
		return "ID:  " + code + "  (" + temp + ")";
	}

	
}
